using System;
using System.Collections;
using UnityEngine;

public static class AnimatorExtensions
{
	public static IEnumerator WaitTillAnimationEnd(this Animator animator, int layer, string state, Action onFinish = null)
	{
		while (!animator.GetCurrentAnimatorStateInfo(layer).IsName(state))
		{
			yield return null;
		}
		AnimatorStateInfo info = animator.GetCurrentAnimatorStateInfo(layer);
		while (info.normalizedTime < 1f)
		{
			yield return null;
			info = animator.GetCurrentAnimatorStateInfo(layer);
		}
		onFinish?.Fire();
	}
}
